/* setCGF.c */
/*Funktionen zum Setzen und Auslesen der Werte in CGF-Objekten Vers. 0.1*/
#include "LoadCGF.h"

#define MORE_SET

/* *********************************************************************** */
   int setTriangleCGF (CGFobject *obj)
/* *********************************************************************** */
/* Setzen eines 3D-Dreiecks nach dem CGF-Format Vers. 0.0 */
{  int jj1=0;
   int i = 0, j = 1, y = 2;

  strcpy(obj->Name,"Triangle CGF Version 0.1");
  obj->nVrtx = 3;

  /*Speicher fuer Eckpunkte reservieren und mit Werten belegen:*/
  obj->Vrtx = (float **) calloc (obj->nVrtx, sizeof(float *));
  for (jj1=0; jj1 < obj->nVrtx; jj1++)
    obj->Vrtx[jj1] = (float *) calloc (NDIM, sizeof(float));
  if (!obj->Vrtx)
  { printf (" setTriangleCGF: kein Speicher fuer Vrtx!"); return (-1); }

  obj->Vrtx[0][X] = -1.;
  obj->Vrtx[0][Y] = -1.;
  obj->Vrtx[0][Z] = -1.;
  obj->Vrtx[0][W] =  1.;

  obj->Vrtx[1][X] =  1.;
  obj->Vrtx[1][Y] = -1.;
  obj->Vrtx[1][Z] = -1;
  obj->Vrtx[1][W] =  1.;

  obj->Vrtx[2][X] =  0.;
  obj->Vrtx[2][Y] =  1.;
  obj->Vrtx[2][Z] = -1.;
  obj->Vrtx[2][W] =  1.;

#define  DOUBLEFACE
#ifdef   DOUBLEFACE
  obj->nFace = 2;
#else  //DOUBLEFACE
  obj->nFace = 1;
#endif //DOUBLEFACE

  /*Speicher fuer Flaechen reservieren und mit Werten belegen:*/
  obj->Face = (Polygon*) calloc (obj->nFace, sizeof(Polygon));
  if (!obj->Face)
  { printf (" setTriangleCGF: kein Speicher fuer Face!"); return (-1); }

  obj->Face[0].nPnt = 3;
#ifdef   DOUBLEFACE
  obj->Face[1].nPnt = 3;
#endif //DOUBLEFACE

  /*Speicher fuer Flaechen-Ecken reservieren und mit Werten belegen:*/
#ifdef   MORE_SET
  /*Speicher fuer Eckpunkte reservieren und mit Werten belegen:*/
    obj->Face.Pnt = (float ***) calloc (obj->Face.nPnt, sizeof(float **));
    for (jj1=0; jj1 < obj->Face.nPnt; jj1++)
      obj->Face.Pnt[jj1] = (float **) calloc (NDIM, sizeof(float *));
    if (!obj->Face.Pnt)
    { printf (" setTriangleCGF: kein Speicher fuer Face.Pnt!"); return (-1); }

    obj->Face[0].Pnt[0][X] = obj->Vrtx[0][X];
    obj->Face[0].Pnt[0][Y] = obj->Vrtx[0][Y];
    obj->Face[0].Pnt[0][Z] = obj->Vrtx[0][Z];

    obj->Face[0].Pnt[1][X] = obj->Vrtx[1][X];
    obj->Face[0].Pnt[1][Y] = obj->Vrtx[1][Y];
    obj->Face[0].Pnt[1][Z] = obj->Vrtx[1][Z];

    obj->Face[0].Pnt[2][X] = obj->Vrtx[2][X];
    obj->Face[0].Pnt[2][Y] = obj->Vrtx[2][Y];
    obj->Face[0].Pnt[2][Z] = obj->Vrtx[2][Z];

    //Rueckseite der Dreiecksflaeche
    obj->Face[1].Pnt[0][X] = obj->Vrtx[2][X];
    obj->Face[1].Pnt[0][Y] = obj->Vrtx[2][Y];
    obj->Face[1].Pnt[0][Z] = obj->Vrtx[2][Z];

    obj->Face[1].Pnt[1][X] = obj->Vrtx[1][X];
    obj->Face[1].Pnt[1][Y] = obj->Vrtx[1][Y];
    obj->Face[1].Pnt[1][Z] = obj->Vrtx[1][Z];

    obj->Face[1].Pnt[2][X] = obj->Vrtx[0][X];
    obj->Face[1].Pnt[2][Y] = obj->Vrtx[0][Y];
    obj->Face[1].Pnt[2][Z] = obj->Vrtx[0][Z];
#endif //MORE_SET

  /*Flaechen Symbole zuweisen:*/
  obj->Face[0].symbol = WHITE;
  //obj->Face[0].symbol = '\60';  // '0'
#ifdef   DOUBLEFACE
  obj->Face[1].symbol = LGREY;
  //obj->Face[1].symbol = '\60'+(char)1;  // '1'
#endif //DOUBLEFACE

  return (1);
}
